package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-09-21
 * Time:21:06
 */
public class AddOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书！");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书的名字");
        String name = scanner.nextLine();
        System.out.println("请输入书的作者");
        String author =scanner.nextLine();
        System.out.println("请输入书的种类");
        String type = scanner.nextLine();
        System.out.println("请输入书的价格");
        int price = scanner.nextInt();

        Book book = new Book(name,author,type,price);
        int size = bookList.getBookSize();
        for (int i = 0; i < size; i++) {
            Book book1 = bookList.getBook(i);
            if (book1.getName().equals(name)){
                System.out.println("这本书已经存在了");
                return;
            }
        }
        bookList.setBook(size,book);
        bookList.setBookSize(size + 1);
        System.out.println("新增图书成功");
    }
}
